//
//  ZYAppleTool.m
//  生活小助手
//
//  Created by 振亚 姜 on 14-8-10.
//  Copyright (c) 2014年 lxz. All rights reserved.
//

#import "ZYAppleTool.h"
#import "XZHttpTool.h"
#import "MJExtension.h"
#import "ZYAppleResult.h"

@implementation ZYAppleTool
/*
 203701	序列号不能为空
 203702	网络错误
 203703	序列号错误或查询不到结果
 203704	您输入的IMEI/MEID/序列号已经被苹果更换
 */
+ (void)getAppleWithParameter:(id)parameter success:(void (^)(id responseObj))success failure:(void (^)(NSError *error))failure
{
    NSDictionary *dictParam = [parameter keyValues];
    
    [XZHttpTool getWithUrl:@"http://apis.juhe.cn/appleinfo/index" parameters:dictParam success:^(NSDictionary *responseObj) {
        int errorcode = [responseObj[@"error_code"] intValue];
        if (errorcode) {
            NSString *domain;
            if (errorcode == 203701) {
                domain = @"序列号不能为空";
            } else if (errorcode == 203702) {
                domain = @"网络错误";
            } else if (errorcode == 203703) {
                domain = @"序列号错误或查询不到结果";
            } else if (errorcode == 203704) {
                domain = @"您输入的IMEI/MEID/序列号已经被苹果更换";
            }
            
            NSError *ipError = [NSError errorWithDomain:domain code:errorcode userInfo:nil];
            if (failure) {
                failure(ipError);
            }
        } else {
            
            id resultObj = [[ZYAppleResult class] objectWithKeyValues:responseObj];
            if (success) {
                success(resultObj);
            }
        }
    } failure:^(NSError *error) {
        NSError *ipError = [NSError errorWithDomain:@"网络无连接" code:[error code] userInfo:error.userInfo];
        if (failure) {
            failure(ipError);
        }
    }];

}

@end
